package org.langcom.logic.schedule;

import java.util.Date;
import java.util.Timer;

import org.joda.time.Instant;
import org.joda.time.MutableDateTime;

public class ScheduleRunner {

	private TimeItem item;
	private Timer timer = new Timer();

	public static void main(String[] args) {
		// TimeItem item = new Week();
		// item.addChild(new DayOfWeek()).addChild(new Hour(11)).addChild(new Minute(35)).addChild(new Second(22));
		// item.addChild(new DayOfWeek(4)).addChild(new Hour(18)).addChild(new Minute(22)).addChild(new Second(22));
		// item.addChild(new DayOfWeek(5)).addChild(new Hour(15)).addChild(new Minute(22)).addChild(new Second(22));
		// new ScheduleRunner(item).start();
		// TimeItem item = new Day();
		// item.addChild(new Hour(11)).addChild(new Minute(35));
		Instant in = new Instant();
		MutableDateTime instance = in.toMutableDateTime();
		instance.setMillis(0);
		// Long nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = item.getNextTime(instance);
		// System.out.println("-------" + item.getType() + "------tt----" + new Date(nextTime));
		// System.out.println("---------------------------------fffffffffffffff------------------");
		// try {
		// String readFileToString = FileUtils.readFileToString(new File("C://my//taxi//qqqq.xml"), "UTF-8");
		// try {
		// XMLBuilder builder = new XMLBuilder();
		// TimeItem timeItem = builder.fromXml(readFileToString);
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = timeItem.getNextTime(instance);
		// System.out.println("---asdASDasd----" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = timeItem.getNextTime(instance);
		// System.out.println("---asdASDasd----" + item.getType() + "------tt----" + new Date(nextTime));
		// instance = new Instant(nextTime).toMutableDateTime();
		// nextTime = timeItem.getNextTime(instance);
		// System.out.println("---asdASDasd----" + item.getType() + "------tt----" + new Date(nextTime));
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		try {
			// String readFileToString = FileUtils.readFileToString(new File("C://my//taxi//qqqq.xml"), "UTF-8");
			// XMLBuilder builder = new XMLBuilder();
			TimeItem timeItem = new Minute(6);
			timeItem.addChild(new Second(22));
			timeItem.addChild(new Second(33));
			timeItem.provideParents();
			MutableDateTime now = new Instant(System.currentTimeMillis()).toMutableDateTime();
			instance = in.toMutableDateTime();
			timeItem.getNextTime(instance, now);
			System.out.println("---asdASDasd-------tt----" + new Date(instance.getMillis()));
			now = new Instant(instance.getMillis()).toMutableDateTime();
			timeItem.getNextTime(instance, now);
			System.out.println("---asdASDasd-------tt----" + new Date(instance.getMillis()));
			now = new Instant(instance.getMillis()).toMutableDateTime();
			timeItem.getNextTime(instance, now);
			System.out.println("---asdASDasd-------tt----" + new Date(instance.getMillis()));
			now = new Instant(instance.getMillis()).toMutableDateTime();
			timeItem.getNextTime(instance, now);
			System.out.println("---asdASDasd-------tt----" + new Date(instance.getMillis()));
			now = new Instant(instance.getMillis()).toMutableDateTime();
			timeItem.getNextTime(instance, now);
			System.out.println("---asdASDasd-------tt----" + new Date(instance.getMillis()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public ScheduleRunner(TimeItem item) {
		this.item = item;
	}

	public void start() {
		// Calendar instance = Calendar.getInstance();
		// instance.setTime(new Date());
		// Long nextTime = item.getNextTime(instance);
		// System.out.println(new Date() + "-------" + item.getType() + "------tt----" + new Date(nextTime));
		// if (nextTime != null) {
		// timer.schedule(new TimerTask() {
		//
		// @Override
		// public void run() {
		// runAction();
		// try {
		// Thread.sleep(1000);
		// } catch (InterruptedException e) {
		// e.printStackTrace();
		// }
		// start();
		// }
		// }, new Date(nextTime));
		// }
	}

	protected void runAction() {
		System.out.println("-------------------runAction--------------");
	}
}
